package AdamsDevice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;

public class RegisterServiceRemote {

   /**
    * The service type you want to register. The first part should be a unique
    * name to identify your services belonging to your project. The second part
    * identifies the transport. The last part identifies the domain. Note that
    * this must end with a period. Service types and transports typically begin
    * with an underscore (e.g. _tcp or _udp). Each part is separated by a
    * period. E.g. "printer._tcp.local.".
    */
   public static final String SERVICE_TYPE = "_film_streaming._udp.local.";

   /**
    * A unique name for the service you want to register; e.g.
    * "casl_level3_colour".
    */
   public static final String SERVICE_NAME = "Test_media_server";

   /**
    * The port on which the service will be listening.
    */
   public static final int SERVICE_PORT = 1269;

   public static void main(String[] args) throws IOException {
      // You can specify the interface that services are registered (and browsed
      // for) on; see the commented lines following.
      JmDNS jmdns = JmDNS.create();
      // JmDNS jmdns = JmDNS.create(InetAddress.getByName("192.168.1.102"));
      // JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());

      ServiceInfo info = ServiceInfo.create(SERVICE_TYPE, SERVICE_NAME, SERVICE_PORT, 0, 0,
            "a_property=some_value");
      jmdns.registerService(info);
      System.out.println("Registered Service as " + info); 
  
      //TODO Added functionality for server
      TCPSocketServer connectionThread = new TCPSocketServer(SERVICE_PORT);
      connectionThread.run();
      
      System.out.println("Press enter to unregister and quit");
      new BufferedReader(new InputStreamReader(System.in)).readLine();
      // Unregister the service.
      jmdns.unregisterService(info);
      jmdns.close();
      System.exit(0);
   }
}
